Completed
Push — master ( 7dfb92...6193f6 )
by Yannick
35:52
created

map.common.js ➔ unitdistance   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
dl 0
loc 5
rs 9.4285
nop 1
1
function getCookie(cname) {
2
    var name = cname + "=";
3
    var ca = document.cookie.split(';');
4
    for(var i=0; i<ca.length; i++) {
5
	var c = ca[i];
6
	while (c.charAt(0)==' ') c = c.substring(1);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7
	if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8
    }
9
    return "";
10
}
11
12
function delCookie(cname) {
13
    document.cookie = cname + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/';
14
}
15
16
function createCookie(name, value, days) {
17
    var date, expires;
18
    if (days) {
19
	date = new Date();
20
	date.setTime(date.getTime()+(days*24*60*60*1000));
21
	expires = "; expires="+date.toGMTString();
22
    } else {
23
	expires = "";
24
    }
25
    document.cookie = name+"="+value+expires+"; path=/";
26
}
27
28
function mapType(selectObj) {
29
    var idx = selectObj.selectedIndex;
30
    var atype = selectObj.options[idx].value;
31
    var type = atype.split('-');
32
    if (type[0] == 'Mapbox') {
33
	createCookie('MapType',type[0],9999);
34
	createCookie('MapTypeId',type[1],9999);
35
    } else {
36
	createCookie('MapType',atype,9999);
37
    }
38
    window.location.reload();
39
}
40
41
function terrainType(selectObj) {
42
    var idx = selectObj.selectedIndex;
43
    var atype = selectObj.options[idx].value;
44
    var type = atype.split('-');
45
    document.cookie =  'MapTerrain='+type+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
46
    createCookie('MapTerrain',type,9999);
47
    window.location.reload();
48
}
49
50
function sattypes(selectObj) {
51
    var sattypes = [], sattype;
52
    for (var i=0, len=selectObj.options.length; i< len;i++) {
53
	sattype = selectObj.options[i];
54
	if (sattype.selected) {
55
	    sattypes.push(sattype.value);
56
	}
57
    }
58
    createCookie('sattypes',sattypes.join(),2);
59
    updateSat();
60
}
61
function airlines(selectObj) {
62
    var airs = [], air;
63
    for (var i=0, len=selectObj.options.length; i< len;i++) {
64
	air = selectObj.options[i];
65
	if (air.selected) {
66
	    airs.push(air.value);
67
	}
68
    }
69
    createCookie('filter_Airlines',airs.join(),2);
70
}
71
function airlinestype(selectObj) {
72
    var idx = selectObj.selectedIndex;
73
    var airtype = selectObj.options[idx].value;
74
    createCookie('filter_airlinestype',airtype,2);
75
}
76
function alliance(selectObj) {
77
    var idx = selectObj.selectedIndex;
78
    var alliance = selectObj.options[idx].value;
79
    createCookie('filter_alliance',alliance,2);
80
}
81
function identfilter() {
82
    var ident = $("#identfilter").value;
83
    createCookie('filter_ident',ident,2);
84
}
85
function mmsifilter() {
86
    var ident = $("#mmsifilter").value;
87
    createCookie('filter_mmsi',ident,2);
88
}
89
function removefilters() {
90
    // Get an array of all cookie names (the regex matches what we don't want)
91
    var cookieNames = document.cookie.split(/=[^;]*(?:;\s*|$)/);
92
    // Remove any that match the pattern
93
    for (var i = 0; i < cookieNames.length; i++) {
94
	if (/^filter_/.test(cookieNames[i])) {
95
	    delCookie(cookieNames[i]);
96
	}
97
    }
98
    window.location.reload();
99
}
100
function sources(selectObj) {
101
    var sources = [], source;
102
    for (var i=0, len=selectObj.options.length; i< len;i++) {
103
	source = selectObj.options[i];
104
	if (source.selected) {
105
	    sources.push(source.value);
106
	}
107
    }
108
    createCookie('filter_Sources',sources.join(),2);
109
}
110
111
112
function show2D() {
113
    createCookie('MapFormat','2d',10);
114
    if (document.getElementById("pointtype").className == 'tracker') {
115
	createCookie('MapTrackTracker',document.getElementById("pointident").className,1);
116
    } else if (document.getElementById("pointtype").className == 'marine') {
117
	createCookie('MapTrackMarine',document.getElementById("pointident").className,1);
118
    } else {
119
	createCookie('MapTrack',document.getElementById("pointident").className,1);
120
    }
121
    window.location.reload();
122
}
123
function show3D() {
124
    createCookie('MapFormat','3d',10);
125
    if (document.getElementById("pointtype").className == 'tracker') {
126
	createCookie('MapTrackTracker',document.getElementById("pointident").className,1);
127
    } else if (document.getElementById("pointtype").className == 'marine') {
128
	createCookie('MapTrackMarine',document.getElementById("pointident").className,1);
129
    } else {
130
	createCookie('MapTrack',document.getElementById("pointident").className,1);
131
    }
132
    window.location.reload();
133
}
134
function clickPolar(cb) {
135
    createCookie('polar',cb.checked,9999);
136
    window.location.reload();
137
}
138
function clickDisplayAirports(cb) {
139
    createCookie('displayairports',cb.checked,9999);
140
    window.location.reload();
141
}
142
function clickDisplayISS(cb) {
143
    createCookie('displayiss',cb.checked,9999);
144
    updateSat();
145
}
146
function clickDisplayMinimap(cb) {
147
    createCookie('displayminimap',cb.checked,9999);
148
    window.location.reload();
149
}
150
function clickSingleModel(cb) {
151
    createCookie('singlemodel',cb.checked,9999);
152
}
153
function clickVATSIM(cb) {
154
    createCookie('filter_ShowVATSIM',cb.checked,2);
155
}
156
function clickIVAO(cb) {
157
     createCookie('filter_ShowIVAO',cb.checked,2);
158
}
159
function clickphpVMS(cb) {
160
    createCookie('filter_ShowVMS',cb.checked,2);
161
}
162
function clickSBS1(cb) {
163
    createCookie('filter_ShowSBS1',cb.checked,2);
164
}
165
function clickAPRS(cb) {
166
    createCookie('filter_ShowAPRS',cb.checked,2);
167
}
168
function clickDisplayGroundStation(cb) {
169
    createCookie('show_GroundStation',cb.checked,2);
170
    window.location.reload();
171
}
172
function clickDisplayWeatherStation(cb) {
173
    createCookie('show_WeatherStation',cb.checked,2);
174
    window.location.reload();
175
}
176
function clickDisplayLightning(cb) {
177
    createCookie('show_Lightning',cb.checked,2);
178
    window.location.reload();
179
}
180
function clickDisplayFires(cb) {
181
    createCookie('show_Fires',cb.checked,2);
182
    window.location.reload();
183
}
184
function clickDisplay2DBuildings(cb) {
185
    createCookie('Map2DBuildings',cb.checked,2);
186
    window.location.reload();
187
}
188
function unitdistance(selectObj) {
189
    var idx = selectObj.selectedIndex;
190
    var unit = selectObj.options[idx].value;
191
    createCookie('unitdistance',unit,9999);
192
}
193
function unitspeed(selectObj) {
194
    var idx = selectObj.selectedIndex;
195
    var unit = selectObj.options[idx].value;
196
    createCookie('unitspeed',unit,9999);
197
}
198
function unitaltitude(selectObj) {
199
    var idx = selectObj.selectedIndex;
200
    var unit = selectObj.options[idx].value;
201
    createCookie('unitaltitude',unit,9999);
202
}
203
function addarchive(begindate,enddate) {
204
    console.log('Add archive');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
205
    createCookie('archive',true,2);
206
    createCookie('archive_begin',begindate,2);
207
    createCookie('archive_end',enddate,2);
208
    createCookie('archive_speed',document.getElementById("archivespeed").value,2);
209
    window.location.reload();
210
}
211
function noarchive() {
212
    console.log('Exit archive!');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
213
    delCookie('archive');
214
    delCookie('archive_begin');
215
    delCookie('archive_end');
216
    delCookie('archive_speed');
217
    window.location.reload();
218
}
219
function msgbox(text,buttontext) {
220
	buttontext = buttontext || "OK";
221
	$("<div>" + text + "</div>").dialog({
222
	    dialogClass: "no-close",
223
	    buttons: [{
224
		text: buttontext,
225
		click: function() {
226
		    $( this ).dialog( "close" );
227
		    $(this).remove();
228
		}
229
	    }]
230
	});
231
}